package com.seckill.controller;

import com.seckill.domain.SeckillActivity;
import com.seckill.service.SeckillActivityService;
import com.seckill.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import com.seckill.domain.Product;
import com.seckill.service.ProductService;

@CrossOrigin
@RestController
@RequestMapping("/product/activity")
public class SeckillActivityController {
    @Autowired
    private SeckillActivityService seckillActivityService;
    @Autowired
    private ProductService productService;

    /**
     * 创建秒杀活动
     */
    @PostMapping("/create")
    public Long create(@RequestBody SeckillActivity seckillActivity) {
        return seckillActivityService.createSeckillActivity(seckillActivity);
    }

    /**
     * 获取所有活动及其商品信息（一个活动对应一个商品）
     */
    @GetMapping("/activity-products")
    public R getAllActivityProducts() {
        return R.OK(seckillActivityService.getAllActivityProducts());
    }

    /**
     * 获取指定活动下的商品信息，activityId为必传参数
     */
    @GetMapping( "/products")
    public R getProductsByActivity(@RequestParam Long activityId) {
        return R.OK(seckillActivityService.getProductsByActivity(activityId));
    }

    // 查询所有活动
    @GetMapping("/list")
    public R getAllActivities() {
        List<SeckillActivity> list = (List<SeckillActivity>) seckillActivityService.getAllActivities();
        return R.OK(list);
    }

    // 查询所有商品
    @GetMapping("/all-products")
    public R getAllProducts() {
        List<Product> list = productService.getAllProducts();
        return R.OK(list);
    }
} 